<?php
/*
                           _
                           \"-._ _.--"~~"--._
                            \   "            ^.    ___
                            /                  \.-~_.-~
                     .-----'     /\/"\ /~-._      /
                    /  __      _/\-.__\L_.-/\     "-.
                   /.-"  \    ( ` \_o>"<o_/  \  .--._\
                  /'      \    \:     "     :/_/     "`
                          /  /\ "\    ~    /~"
                          \ I  \/]"-._ _.-"[
                       ___ \|___/ ./    l   \___   ___
                  .--v~   "v` ( `-.__   __.-' ) ~v"   ~v--.
               .-{   |     :   \_    "~"    _/   :     |   }-.
              /   \  |           ~-.,___,.-~           |  /   \
             ]     \ |                                 | /     [
             /\     \|     :                     :     |/     /\
            /  ^._  _K.___,^                     ^.___,K_  _.^  \
           /   /  "~/  "\                           /"  \~"  \   \
          /   /    /     \ _          :          _ /     \    \   \
        .^--./    /       Y___________l___________Y       \    \.--^.
        [    \   /        |        [/    ]        |        \   /    ]
        |     "v"         l________[____/]________j         }r"     /
        }------t          /                       \       /`-.     /
        |      |         Y                         Y     /    "-._/
        }-----v'         |         :               |     7-.     /
        |   |_|          |         l               |    / . "-._/
        l  .[_]          :          \              :  r[]/_.  /
         \_____]                     "--.             "-.____/

                                            
                                                      
         
        */
/**
 * Created by PhpStorm.
 * User: hengge
 * Date: 2018/6/14
 * Time: 18:52
 */
namespace app\index\controller;

use think\Controller;
use think\Request;

class Common extends Controller{
    public $category;
    protected $model_data;  //获取当前model数据信息
    public $setting;
    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        //检查是否自动安装
        if(!file_exists(APP_PATH.'install.lock')){
            $this->redirect(url('/install/index'));

        }

        //获取设置
        $this->setting=model('setting')->getSetting();
        $this->assign('setting',$this->setting);
        if($this->setting['site_status'] == 0){
            $this->redirect('/404.html');
        }


        //动态设置模板
        $this->view->config('view_path','./template/'. $this->setting['template_name'] .'/');
        //动态设置模板替换变量
        $this->view->replace('__TEMPLATE__','/template/' . $this->setting['template_name']);

        //如果是pjax 修改ajax 返回类型
        if($this->request->isPjax()){
            config('default_ajax_return','html');
        }



        //获取头部导航
        $this->category=model('category')->homeGetCategoryTreeArray();
        $this->assign('category',$this->category);


        $request= Request::instance();
        //根据当前controller获取模型数据

        $this->model_data=model('admin/models')->adminGetModelDataToTableName(strtolower($request->controller()));

    }
}